﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StoreClientModule;

namespace MBBStoreClient
{
    public partial class frmMyAccount : Form
    {
        UserManager um = new UserManager();
        public frmMyAccount()
        {
            InitializeComponent();

            btnClose.Click += new EventHandler(btnClose_Click);
            panel2.EnabledChanged += new EventHandler(panel2_EnabledChanged);

            btnCommit.Click += new EventHandler(btnCommit_Click);
            um.ProcessCompleted += new ModuleEventsHandler(um_ProcessCompleted);
        }

        void um_ProcessCompleted(int procCode, string msg)
        {
            uCoreClasses.uThreader t = new uCoreClasses.uThreader();
            t.SafeCall(this, delegate
            {
                pnlForm.Dispose();
                this.Dispose();
            });
        }

        void btnCommit_Click(object sender, EventArgs e)
        {
            if (txtOld.Text == Common.Password)
            {
                if (txtNew.Text == txtConfirm.Text)
                {
                    UserType[] ut = new UserType[2];
                    ut[0].Username = Common.Username;
                    ut[0].Password = txtNew.Text;
                    ut[1].Username = Common.Username;
                    ut[1].Password = Common.Password;

                    um.Update(ut);
                }
                else
                {
                    lblNotice.Text = "New Password and Confirm Password does not match.";
                }
            }
            else
            {
                lblNotice.Text = "Old Password does not match.";
            }
        }


        void panel2_EnabledChanged(object sender, EventArgs e)
        {
            if (!panel2.Enabled)
            {
                panel2.BackColor = Color.MidnightBlue;
            }
            else
            {
                panel2.BackColor = Color.RoyalBlue;
            }
        }
        void btnClose_Click(object sender, EventArgs e)
        {
            pnlForm.Dispose();
            this.Dispose();
        }
        public Panel PanelForm
        {
            get { return pnlForm; }
        }
        public void Initialize(string Title)
        {
            this.Select();
            lblText.Text = Title;
        }
    }
}
